﻿using System;
using Wintellect.Sterling.Database;
using Caramel.Entities;

namespace Caramel.Sterling.Entities
{
	public class MutableTrigger<T, TKey> : BaseSterlingTrigger<T, TKey> where T : class, new()
	{
		public override void AfterSave(T instance)
		{
			return;
		}

		public override bool BeforeDelete(TKey key)
		{
			return true;
		}

		public override bool BeforeSave(T instance)
		{
			var mutable = instance as IMutable;

			if (mutable != null)
			{
				mutable.Updated = SystemTime.Now;
				mutable.UpdatedBy = CurrentUser.Name;
			}

			return true;
		}
	}
}
